<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
class Slideshow extends Controller{
    public function slideshowlist(){
        $sql = "select * from man_advertisement";
        $data = Db::query($sql);
        return view('slideshowlist',['data'=>$data]);
    }
    public function addslideshow(){
        return view('addslideshow');
    }
    public function addslideshowdo(){
        $data = input();
        $a_img = $_FILES['a_img'];
        $path = 'upload/'. time() .$a_img['name'];
        move_uploaded_file($a_img['tmp_name'],$path);
        $time = time();
        $sql = "insert into man_advertisement values ('','".$data['a_name']."','$path','$time',0,'".$data['a_text']."','".$data['a_type']."')";
        $res = Db::execute($sql);
        if ($res){
            $this->redirect('admin/slideshow/slideshowlist');
        }

    }
    public function slideshowup(){
        $id = $_GET['a_id'];
        $sql = "select * from man_advertisement where a_id='$id'";
        $res = Db::query($sql);
        if ($res) {
            return view('slideshowup',['res'=>$res[0]]);
        }

    }
    public function addslideshowupdo(){
        $data = input();
        $a_img = $_FILES['a_img'];
        $path = 'upload/'. time() .$a_img['name'];
        move_uploaded_file($a_img['tmp_name'],$path);
        $time = time();
        $sql = "update man_advertisement set a_name='".$data['a_name']."',a_img='$path',a_addtime='$time',a_statc=0,a_text='".$data['a_text']."',a_type='".$data['a_type']."' where a_id = '".$data['a_id']."'";
        $res = Db::execute($sql);
        if ($res){
            $this->redirect('admin/slideshow/slideshowlist');
        }
    }
    public function slideshowdel(){

        $id = $_GET['a_id'];
        $res = Db::table('man_advertisement')->where('a_id='.$id)->delete();
        if ($res){
            $this->redirect('admin/slideshow/slideshowlist');
        }
    }
    public function isshow()
    {
        $id = input('get.a_id');
        $g_statc = input('get.p');
        $sql = "update man_advertisement set a_statc=0 where a_id='$id'";
        $res = Db::execute($sql);
        if ($res)
        {
            return 1;
        }
    }
    public function bshow()
    {
        $id = input('get.a_id');
        $g_statc = input('get.p');
        $sql = "update man_advertisement set a_statc=1 where a_id='$id'";
        $res = Db::execute($sql);
        if ($res)
        {
            return 1;
        }
    }

}